package com.peng.leetcode.other;

import java.util.ArrayList;
import java.util.List;

/**
 * LargeGroupPositions
 *
 * @author: lupeng6
 * @create: 2021/1/5 16:37
 */
public class LargeGroupPositions {

    public static void main(String[] args) {
        String s = "aaa";
        List<List<Integer>> lists = new Solution().largeGroupPositions(s);
        System.out.println(lists);
    }

    static class Solution {
        public List<List<Integer>> largeGroupPositions(String s) {
            List<List<Integer>> lists = new ArrayList<>();
            int len = s.length();
            int num = 1;
            for (int i = 0; i < len; i++) {
                char c = s.charAt(i);
                if (i == len - 1 || c != s.charAt(i + 1)) {
                    if (num >= 3) {
                        List<Integer> l = new ArrayList<>();
                        l.add(i - num + 1);
                        l.add(i);
                        lists.add(l);
                    }
                    num = 1;
                } else {
                    num++;
                }
            }
            return lists;
        }
    }
}
